<div id="div2_chart"></div>
<script>

    var kategori = [];
    var series = [];
    var kat = [];
    var ser = [];
    var ser2 = [];
<?php

//var_dump($data);

function format_angka($angka) {
    $len = strlen($angka);
    $res = "";
    $c = 0;
    while ($len > 0) {
        $len--;
        $res = $angka[$len] . $res;
        $c = ($c + 1) % 3;
        if ($c == 0 && $len > 0)
            $res = "." . $res;
    }
    return $res;
}

$counter = 0;
foreach ($data as $pekerjaan) {
    $counter++;
    if (isset($limit))
        if ($counter > $limit)
            break;
    ?>

        kat.push("<?= $pekerjaan->kategori ?>");
        ser.push(<?= $pekerjaan->jumlah1 ?>);
        ser2.push(<?= $pekerjaan->jumlah2 ?>);
    <?php
}
?>
//    $('#div_chart').prepend('<div id="div2_chart"></div>');
    $('#div2_chart').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: '<?= $judul ?>'
        },
        subtitle: {
            text: '<?php
if (isset($subtitle))
    echo implode('-', $subtitle);
else
    echo 'Banyuwangi';
?>'
        },
        xAxis: {
            categories: kat,
            labels: {
                rotation: -45,
                style: {
                    fontFamily: 'Verdana, sans-serif'
                }
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Jumlah (orang)'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                    '<td style="padding:0"><b>{point.y:.0f} orang</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        series: [{
                name: 'Jumlah Miskin',
                data: ser,
            },
            {
                name: 'Jumlah Total',
                data: ser2,
            }]
    });

</script>
<?php
$session = $this->session->userdata('login');
$logged_in = false;
if ($session != null) {
    $logged_in = true;
}
?>
<div style="margin-top: 40px">
    <table class="table table-striped">
        <tr>
            <th>No.</th>
            <th><?= $kolom_tabel ?></th>
            <th style="text-align: right">Jumlah Miskin</th>
            <th style="text-align: right">Jumlah Total</th>
            <?php
            if ($logged_in) {
                ?>
                <th>Aksi</th>
                <?php
            }
            ?>
        </tr>
        <?php
        $tot = 0;
        $tot2 = 0;
        $no = 0;
        foreach ($data as $row) {
            $no++;
            $tot = $tot + $row->jumlah1;
            $tot2 = $tot2 + $row->jumlah2;
            ?>
            <tr>
                <td><?= $no ?></td>
                <td><?= $row->kategori; ?></td>
                <td style="text-align: right"><?= format_angka($row->jumlah1); ?></td>
                <td style="text-align: right"><?= format_angka($row->jumlah2); ?></td>
                <?php
            if ($logged_in) {
                ?>
                <td>
                <a href="<?= site_url() . '/' . $controller ?>?<?= (isset($id_kecamatan)&&$id_kecamatan>0?'id_kecamatan='.$id_kecamatan.'&id_kelurahan':'id_kecamatan') ?>=<?= $row->kategori_id ?>">Lihat</a>
                </td>
                <?php
            }
            ?>
            </tr>
            <?php
        }
        ?>
        <tr>
            <td></td>
            <td>Total</td>
            <td style="text-align: right"><?= format_angka($tot . ""); ?></td>
            <td style="text-align: right"><?= format_angka($tot2 . ""); ?></td>
            <?php
            if ($logged_in) {
                ?>
                <td>
                <a href="<?= site_url() . '/' . $controller ?>">Lihat</a>
                </td>
                <?php
            }
            ?>
        </tr>
    </table>
</div>